<?php
namespace Admin\Controller;
use Common\Controller\CommonController;
class ImageController extends CommonController{
	/**
	 * 图片上传
	 */
	public function uploadImage(){
		$file = $_FILES['image'];
		$r = $this->upload($file);
		if($r['status']!=1){
			$data = [
				'status'=>-1,
				'msg'=>$r['msg']
			];
			$this->ajaxReturn($data);
		}
		$data = [
		'status'=>1,
		'url'=>$r['url'],
		'msg'=>'上传成功'
		];
		$this->ajaxReturn($data);
	}
	public function uploadtt($file){
		 
		switch($file['type'])
		{
			case 'image/jpeg': $ext = 'jpg'; break;
			case 'image/gif': $ext = 'gif'; break;
			case 'image/png': $ext = 'png'; break;
			case 'image/tiff': $ext = 'tif'; break;
			default: $ext = ''; break;
		}
		if (empty($ext)){
			return false;
		}
		$upload = new \Think\Upload();// 实例化上传类
		$upload->maxSize   =     3145728 ;// 设置附件上传大小
		$upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
		$upload->savePath  =      './Public/Uploads/'; // 设置附件上传目录
		// 上传文件
		$info   =  $upload->uploadOne($file);
		$data = [];
		if(!$info) {
			// 上传错误提示错误信息
			$data = [
			'status'=>-1,
			'msg'=>$upload->getError(),
			];
		}else{
			// 上传成功
			$pic=$info['savepath'].$info['savename'];
			$url='/Uploads'.ltrim($pic,".");
			$data = [
			'status'=>1,
			'url'=>$url,
			];
		}
		return $data;
	}
}